package com.jiapu.controller;

import com.jiapu.common.Result;
import com.jiapu.entity.Event;
import com.jiapu.mapper.EventMapper;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/event")
public class EventController {

    @Resource
    EventMapper eventMapper;

    @GetMapping("/total")
    public int getTotalCount() {
        return eventMapper.getTotalCount();
    }

    @GetMapping("/list")
    public Result getEventList(@RequestParam("currentPage") int currentPage, @RequestParam("pageSize") int pageSize) {
        int offset = (currentPage - 1) * pageSize;
        return  Result.success(eventMapper.getEvent(offset, pageSize));
    }

    @GetMapping("/search")
    public Result list(@RequestParam(value="search") String people_name){
        List<Event> eventSearchList = eventMapper.search(people_name);
        return Result.success(eventSearchList);
    }

    @PostMapping
    public String addEvent(@RequestBody Event event){
        eventMapper.save(event);
        return "success";
    }

    @PutMapping
    public String updateEvent(@RequestBody Event event){
        eventMapper.updateById(event);
        return "success";
    }

    @PutMapping("/del")
    public String deleteEvent(@RequestBody Event event){
        eventMapper.deleteById(event);
        return "success";
    }

}

//    @GetMapping("/get")
//    public List<Event> getEvent(){
//
//        return eventMapper.findAll();
//    }
//
//    @PostMapping("/post")
//    public String addEvent(@RequestBody Event event){
//        eventMapper.save(event);
//        return "success";
//    }
//
//    @PutMapping("/put")
//    public String updateEvent(@RequestBody Event event){
//        eventMapper.updateById(event);
//        return "success";
//    }
//
//    @PutMapping("/del")
//    public String deleteEvent(@RequestBody Event event){
//        eventMapper.deleteById(event);
//        return "success";
//    }


//    @GetMapping("/search")
//    public  Result getEventSearch(){
//        List<Event> eventSearchList = eventMapper.search();
//        return Result.success(eventSearchList);
//    }
//    @GetMapping
//    public List<Event> getEvent(@RequestParam(defaultValue = "1") Integer pageNum,
//                                @RequestParam(defaultValue = "10") Integer pageSize,
//                                @RequestParam(defaultValue = "") String search) {
//        LambdaQueryWrapper<Event> wrapper = Wrappers.<Event>lambdaQuery();
//        if(StringUtils.isNotBlank(search)){
//            wrapper.like(Event::getPeople_name,search);
//        }
//        Page<Event> eventPage= eventMapper.selectPage(new Page<>(pageNum, pageSize),wrapper);
//        return eventMapper.findAll();
//    }